package com.kcht.rfid.rd30.secretary.dispatch.impl.operation;

import com.kcht.rfid.rd30.secretary.core.command.BasicReaderCommand;
import com.kcht.rfid.rd30.secretary.core.common.ReaderResponseStatus;
import com.kcht.rfid.rd30.secretary.core.response.InventoryResponse;
import com.kcht.rfid.rd30.secretary.dispatch.IReaderChannel;
import lombok.extern.slf4j.Slf4j;
import uhf_msg.Uhf;

import java.time.LocalDateTime;
import java.util.Observer;

/**
 * 清点操作
 * */
@Slf4j
public class Invent extends BaseOperation {

    public Invent(Observer observer) {
        super(observer);
    }

    @Override
    protected void handlerOperation(IReaderChannel channel, Uhf.uhf_response response, Integer antId, BasicReaderCommand command) {
        String[] resList = response.getEpcInventRes().toString().split(" ");
        Uhf.uhf_response.EpcInventResponse epcInventRes = response.getEpcInventRes();
        String epc = resList[resList.length-1];
        epc=epc.substring(1,epc.length()-2);
        log.info("清点到标签--->ip:{},天线接口:{},epc:{}",channel.getIp(),antId,epc);
        InventoryResponse inventoryResponse=new InventoryResponse();
        inventoryResponse.setRssi(epcInventRes.getRssi());
        inventoryResponse.setEpc(epc);
        inventoryResponse.setDateTime(LocalDateTime.now());
        inventoryResponse.setEpc(epc);
        inventoryResponse.setIp(channel.getIp());
        inventoryResponse.setAntId(antId);
        inventoryResponse.setStatus(ReaderResponseStatus.成功);
        super.response(inventoryResponse);
    }
}
